package com.xbs.controller.hitchhiking;

import java.io.IOException;
import java.sql.Timestamp;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xbs.controller.base.BaseServlet;
import com.xbs.controller.enterprise.DateJsonValueProcessor;
import com.xbs.entity.CommonOrderEntity;
import com.xbs.entity.EmployeeEntity;
import com.xbs.entity.TimeEntity;
import com.xbs.service.hitchhiking.EmpAdminService;
import com.xbs.service.hitchhiking.HitchOrderAdminService;

import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import net.sf.json.util.CycleDetectionStrategy;
/**
 * 第二次修改顺风车的订单
 * 还车时的修改操作
 * @author dell
 */
@WebServlet("/backstage/xghoajax2")
public class XgHitchOrderAjaxServlet2 extends BaseServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
HitchOrderAdminService hoas = new HitchOrderAdminService();
		
		/**
		 * 根据订单编号进行还车修改
		 */
		CommonOrderEntity coe = new CommonOrderEntity();
		TimeEntity te = new TimeEntity();
		String ddid2 = req.getParameter("ddid2");
		String time2 = req.getParameter("time2");
		Timestamp returntime = new Timestamp(System.currentTimeMillis());
		returntime = Timestamp.valueOf(time2);
		int row = hoas.updateReturnTime(te);
		
		te.setTime_fact_get(returntime);
		coe.setCo_id(ddid2);
		
		List<CommonOrderEntity> coelst = hoas.selOrderByReturn(coe);
	
		JsonConfig jsonConfig = new JsonConfig();   
		jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);   
		jsonConfig.registerJsonBeanProcessor(java.sql.Date.class, new DateJsonValueProcessor());  
		jsonConfig.setExcludes(new String[]{"handler","hibernateLazyInitializer"});    
		//JSONArray jsonArray = JSONArray.fromObject(xgemp.getIst(),jsonConfig);
		JSONObject obj = null;
		if(coelst.size()>0){
			obj =JSONObject.fromObject(coelst.get(0),jsonConfig); 
		}
	
		resp.getWriter().print(obj);
	}
}
